import pymongo


def getClient():
    myClient = pymongo.MongoClient("mongodb://localhost:27017/")
    return myClient


def find(client):
    myDb = client["w3cschooldb"]
    myCol = myDb["sites"]

    # 查询单条
    x = myCol.find_one()
    print(x)

    # 查询所有
    for x in myCol.find():
        print(x)

    # 投影查询
    for x in myCol.find({}, {"name":1}):
        print(x)
    # 条件查询
    for x in myCol.find({"name":"知乎"}):
        print(x)

    print("----")
    for x in myCol.find({"name":{"$gt":"H"}}):
        print(x)


if __name__ == "__main__":
    client = getClient()
    find(client)
